<?php
namespace app\admin\controller;

use app\common\logic\Logic;
use think\Db;


class Banner extends Base
{

    function _initialize()
    {
        parent::_initialize();
        $this->assign('stamp',123);
    }

    public function index()
    {
        $where = [];
        if(!empty($_GET['title'])){
            $where['b.title'] = ['like','%'.trim(input('get.title')).'%'];
        }
        if(!empty($_GET['cid'])){
            $where['b.cid'] = trim(input('get.cid'));
        }
        if(!isEmpty($_GET['status'])){
            $where['b.status'] = trim(input('get.status'));
        }
        $model = new \app\common\model\Banner();
        $rows = $model->getList($where);
        $data = Db::name('banner_cate')->where('status',1)->select();
        $this->assign([
            'title' => '轮播图列表',
            'data' => $data,
            'pageHTML' => $rows->render(),
            'rows' => $rows
        ]);
        return view();
    }

    public function edit()
    {
        if(request()->isPost()){
            $data   = input('post.');

            $model  = new Logic();
            $result = $model->saveChange('banner',$data,'banner');
            if($result !== false){
                $this->success('修改成功',url('index'));
            }
            $this->error($model->getError());
        }
        $where['status'] = 1;
        $this->_show('banner','bid','banner_cate','',$where);
        $this->assign('title','图片编辑');
        return view();
    }

    public function change()
    {
        $this->_change('banner');
    }

    public function del()
    {
        $this->_del('banner');
    }

    public function cate()
    {
        $this->_list2('banner_cate','cid DESC');
        $this->assign('title','图片列表');
        return view();
    }


    public function cate_edit()
    {
        $this->_edit('banner_cate','banner分类编辑',url('cate'),'banner_cate');
        return view();
    }

    public function cate_change()
    {
        $this->_change('banner_cate');
    }

    public function cate_del()
    {
        $this->_del('banner_cate');
    }



}
